#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

if [[ $(bundler -v) == *"$BUNDLER_VERSION"* ]]; then
  echo "Bundler version matches desired version: ${BUNDLER_VERSION}"
else
  echo "Bundler version $(bundler -v) does not match desired version: ${BUNDLER_VERSION}"
  exit 1
fi

# Check there's no differences after re-initialising
ruby -I ../../lib ../../bin/bundler-checksum init
git diff --exit-code Gemfile.checksum

# Verify against rubygems.org
ruby -I ../../lib ../../bin/bundler-checksum verify

# Test installing with bundler-checksum
export BUNDLER_CHECKSUM_VERIFICATION_OPT_IN=1
bundle install

# Ensure that each gem has a valid checksum entry
ruby -I ../../lib ../../bin/bundler-checksum lint
